package com.future.mayi.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.HttpRequest;
import com.future.mayi.R;
import com.future.mayi.utils.HtmlFormat;
import com.future.mayi.utils.KefuUtils;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 鉴定规则页面
 */
public class AppraisalRulesActivity extends BaseTitleActivity {
    @BindView(R.id.web_view)
    WebView webView;
    @BindView(R.id.tv_enter)
    TextView tvEnter;

    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("鉴定");
        getRightImg().setImageResource(R.drawable.bottom_kefu);
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_rules_appraisala);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDates() {
        new HttpRequest<DefaultResponse>()
                .with(this)
                .setApiCode(ApiCst.commonJd)
                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
                    @Override
                    public void onSuccess(DefaultResponse response) {
                        String data = response.content;
                        if (!TextUtils.isEmpty(data)) {
                            JSONObject object = null;
                            try {
                                object = new JSONObject(data);
                                String info = object.optString("info");
                                if (info == null) return;
                                webView.loadDataWithBaseURL(null, HtmlFormat.getNewContent(info), "text/html", "utf-8", null);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                    @Override
                    public void onFail(String message, DefaultResponse response) {

                    }
                })
                .start(new DefaultResponse());
    }

    @Override
    protected void initListener() {
        getRightImg().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                KefuUtils.startActivity(mContext);
            }
        });
    }


    @OnClick(R.id.tv_enter)
    public void onViewClicked() {
        startActivity(new Intent(AppraisalRulesActivity.this, AppraisalActivity.class));
        finish();
    }
}
